package com.gancp.utills;

import com.gancp.common.Constans;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by GCP on 2018/5/3.
 * 日期工具类
 */
public class DateUtils {
    private SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm" );
    private static Calendar calendar = Calendar.getInstance();
    // 中午12点
    public static final int NOON_HOUR = 12;
    // 某个小时的整数点
    public static final int NOON_MINUTE = 00;

    public static final int MORING_WORK_TIME = 0;

    public static final int EVENING_ENDWORK_TIME = 1;

    private DateUtils() {
    }

    /**
     * @Author gancp
     * @Date 时间被黑洞吸走了
     * @Descripition 取得今天是星期几
     **/
    public static int getTodayWeek() {
        calendar = Calendar.getInstance();
        calendar.setTime( new Date() );
        int week = calendar.get( Calendar.DAY_OF_WEEK );
        return week - 1 <= 0 ? 7 : week - 1;
    }

    /**
     * @Author gancp
     * @Date 时间被黑洞吸走了
     * @Descripition 计算时间差 返回分钟数
     **/
    public static int getMinute(Date startDate, Date endDate) {
        long start = startDate.getTime();
        long end = endDate.getTime();
        int minute = (int) (Math.abs( end - start ) / (1000 * 60));
        return minute;
    }

    /**
     * @Author gancp
     * @Date 时间被黑洞吸走了
     * @Descripition 获取当日某个时间段的日期
     **/
    public static Date getDate(int hour, int minute) {
        calendar.set( Calendar.HOUR_OF_DAY, hour );
        calendar.set( Calendar.MINUTE, minute );
        Date date = calendar.getTime();
        return date;
    }

    public static Date getWorkDate(int index) {
        if (index == MORING_WORK_TIME) {
            return getDate( Constans.MORING_WORK_TIME[0], Constans.MORING_WORK_TIME[1] );
        }
        if (index == EVENING_ENDWORK_TIME) {
            return getDate( Constans.EVENING_ENDWORK_TIME[0], Constans.EVENING_ENDWORK_TIME[1] );
        }
        return new Date();
    }

    public static Date getYestaryDay() {
        calendar.setTime( new Date() );
        calendar.add( Calendar.DATE, -1 );
        Date yestaryDay = new java.sql.Date( calendar.getTime().getTime() );
        return yestaryDay;
    }

    public static void main(String[] args) {
        System.out.println( getYestaryDay() );
    }

}
